import { defineStore } from 'pinia'
import adminApi from '@/api/admin'
import { useUserStore, useAuthStore } from './'

export const useAdminStore = defineStore('admin', {
  state: () => ({
    admin: null,
  }),
  getters: {},
  actions: {
    async getAdmin() {
      try {
        const userStore = useUserStore()
        const res = await adminApi.getAdmin(userStore.user_id)
        this.admin = res.data
        useAuthStore().setHasName(this.admin.name!==null)
        return Promise.resolve(res.data)
      } catch (error) {
        return Promise.reject(error)
      }
    },
    resetRecruiter() {
      this.$reset()
    },
  },
})
